﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.Auth.Api.Application.Command;
using Service.Auth.Api.Application.Query;
using Service.Auth.Model.Model.Dto;
using Service.Auth.Model.Model.QueryDto;
using Service.Auth.Model.Model.RequestDto.Permissions;
using Service.Core.Filters;
using Service.Core.Identity.Model;

namespace Service.Auth.Api.Controller
{
    /// <summary>
    /// 权限控制器
    /// </summary>
    [Authorize(Policy = AuthPolicy.Permission)]
    public class PermissionsController(IMediator mediator, PemissionsQueryService queryService) : BaseController(mediator)
    {
        /// <summary>
        /// 创建菜单-按钮
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [OperateLogFilter("菜单管理", "创建菜单")]
        public async Task<bool> CreatePermissions([FromBody] CreatePermissionsDto dto)
        {
            var command = new CreatePermissionsCommand(dto);
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 修改菜单-按钮
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [OperateLogFilter("菜单管理", "修改菜单")]
        public async Task<bool> UpdatePermissions([FromBody] UpdatePermissionsDto dto)
        {
            var command = new UpdatePermissionsCommand(dto);
            return await _mediator.Send(command);
        }


        /// <summary>
        /// 删除菜单-按钮
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        [OperateLogFilter("菜单管理", "删除菜单")]
        public async Task<bool> DeletePermissions([FromBody] DeletePermissionsDto dto)
        {
            var command = new DeletePermissionsCommand(dto);
            return await _mediator.Send(command);
        }


        /// <summary>
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<PermissionDto>> QueryPemissions([FromQuery] QueryPemissionsModel condition)
        {
            return await queryService.QueryPemissions(condition);
        }


    }
}